# -*- coding:utf-8 -*-
#! python3

# FaceCat-Python
#Shanghai JuanJuanMao Information Technology Co., Ltd 

import os
from tkinter import *
from facecat_tkinter import *

def mousePressEvent(event):
	global gPaint
	mp = FCPoint(event.x, event.y)
	mp.x /= gPaint.scaleFactorX
	mp.y /= gPaint.scaleFactorY
	handleMouseDown(mp, 1, 1, 0, gPaint)
def mouseReleaseEvent(event):
	global gPaint
	mp = FCPoint(event.x, event.y)
	mp.x /= gPaint.scaleFactorX
	mp.y /= gPaint.scaleFactorY
	if gPaint.isDoubleClick:
		handleMouseUp(mp, 1, 2, 0, gPaint)
	else:
		handleMouseUp(mp, 1, 1, 0, gPaint)
def mouseMoveEvent(event):
	global gPaint
	mp = FCPoint(event.x, event.y)
	mp.x /= gPaint.scaleFactorX
	mp.y /= gPaint.scaleFactorY
	if gPaint.touchDownView != None:
		handleMouseMove(mp, 1, 1, 0, gPaint)
	else:
		handleMouseMove(mp, 0, 0, 0, gPaint)
def mouseDoubleClickEvent(event):
	global gPaint
	mp = FCPoint(event.x, event.y)
	mp.x /= gPaint.scaleFactorX
	mp.y /= gPaint.scaleFactorY
	handleMouseDown(mp, 1, 2, 0, gPaint)
def wheelEvent(event):
	global gPaint
	mp = FCPoint(event.x, event.y)
	mp.x /= gPaint.scaleFactorX
	mp.y /= gPaint.scaleFactorY
	delta = event.delta
	handleMouseWheel(mp, 0, 0, delta, gPaint)

root = Tk()
root.geometry('800x750')
canvasSize = FCSize(800, 750)
mycanvas = Canvas(root, width=canvasSize.cx,height=canvasSize.cy)
mycanvas.pack()
mycanvas.bind("<Button-1>", mousePressEvent)
mycanvas.bind("<ButtonRelease-1>", mouseReleaseEvent)
mycanvas.bind("<Motion>", mouseMoveEvent)
mycanvas.bind("<Double-Button-1>", mouseDoubleClickEvent)
mycanvas.bind("<MouseWheel>", wheelEvent)

gPaint = FCPaint() #创建绘图对象
gPaint.defaultUIStyle = "dark"
current_file_path = os.path.abspath(__file__)
current_file_dir = os.path.dirname(current_file_path)
file0 = open(current_file_dir + "\\mainframe.xml", encoding="UTF-8")
xml = file0.read()
file0.close()
gPaint.canvas = mycanvas
gPaint.root = root
gPaint.size = canvasSize
renderFaceCat(gPaint, xml)
root.mainloop()